/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.lzh.compiler.parcelerdemo;

import com.lzh.compiler.parcelerdemo.base.BaseAbility;
import ohos.aafwk.content.Intent;
import ohos.utils.Parcel;
import ohos.utils.Sequenceable;

/**
 * ParcelerDemo.
 */
public class TestCastAbility extends BaseAbility {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_test_cast_ablity);
    }

    void checkForNull(Object obj, String name) throws Exception {
        if (obj == null) {
            throw new RuntimeException(String.format(
                    "检查到检查对象TestCastActivity.%s为null,数据转换兼容失败", name
            ));
        }
    }

    /**
     * SubParcelable.
     */
    public static class SubParcelable implements Sequenceable {
        private int data = 0;

        public SubParcelable() {
        }

        protected SubParcelable(Parcel in) {
        }

        @Override
        public boolean hasFileDescriptor() {
            return false;
        }

        @Override
        public boolean marshalling(Parcel parcel) {

            parcel.writeString(getClass().getName());
            parcel.writeInt(data);
            return false;
        }

        @Override
        public boolean unmarshalling(Parcel parcel) {
            return false;
        }
    }
}